define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'report/template/index' + location.search,
                    // add_url: 'report/template/add',
                    edit_url: 'report/template/edit',
                    // del_url: 'report/template/del',
                    multi_url: 'report/template/multi',
                    // import_url: 'report/template/import',
                    table: 'report_template',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'template_id',
                sortName: 'template_id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'template_id', title: __('Template_id')},
                        {field: 'template_name', title: __('Template_name'), operate: 'LIKE'},
                        {field: 'report_type', title: __('Report_type')},
                        {
                            field: 'business_type', title: __('Business_type'), formatter: function (row) {
                                if (row.business_type) {
                                    return '食品销售'
                                }
                                return '餐饮'
                            }
                        },
                        {field: 'min_item_nums', title: __('Min_item_nums')},
                        {field: 'sort', title: __('排序')},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
